package com.pjedu.nbmalladminsystem.config;

import com.pjedu.nbmalladminsystem.interceptor.AdminLoginInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

/**
 * @Author 汪洋
 * @Description
 * 用来进行配置哪些请求需要过拦截器,哪些不需要过拦截器的
 * 拦截规则:
 *      a、主页的访问不过拦截器;
 *      b、验证码的访问不过拦截器;
 *      c、后续有关login的所有操作都不过拦截器;
 *      d、所有静态资源文件的访问不过拦截器,比如js、css、img、fonts、plugins等
 *      e、所有错误显示不过拦截器
 */
@Configuration
public class InterceptorConfig implements WebMvcConfigurer {
    @Resource
    private AdminLoginInterceptor adminLoginInterceptor;
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //设置拦截规则对哪个拦截器生效
        registry.addInterceptor(adminLoginInterceptor)
                //设置需要拦截的请求,这里是设置成所有请求都拦截
                .addPathPatterns("/**")
                //以下是不需要拦截的情况
                .excludePathPatterns("/index.html")
                .excludePathPatterns("/admin/login")
                .excludePathPatterns("/admin/login/**")
                .excludePathPatterns("/")
                .excludePathPatterns("/js/**")
                .excludePathPatterns("/img/**")
                .excludePathPatterns("/css/**")
                .excludePathPatterns("/plugins/**")
                .excludePathPatterns("/fonts/**")
                .excludePathPatterns("/upload/**")
                .excludePathPatterns("/test.html")
                .excludePathPatterns("/error");
    }
}
